package ten.test_10_25;

import java.util.Scanner;

public class TestMain2 {
    public  static long max = Integer.MIN_VALUE;
    public static long minY = Integer.MAX_VALUE;
    public static long maxY = Integer.MIN_VALUE;
    public  static boolean[] b;
    public static void main(String[] args) {
        Scanner scanner = new Scanner(System.in);
        int n = scanner.nextInt();
        int k = scanner.nextInt();
        long[][] arr = new long[n][2];
        b = new boolean[n];
        for (int i = 0; i < n; i++) {
            arr[i][0] = scanner.nextLong();
            arr[i][1] = scanner.nextLong();
        }
        for (int i = 0; i < n; i++) {
            long y1 = minY;
            long y2 = maxY;
            minY = Math.min(arr[i][0], minY);
            maxY = Math.max(arr[i][0], maxY);
            b[i] = true;
            dfs(arr,k,arr[i][1],i);
            b[i] = false;
            minY = y1;
            maxY = y2;
        }
        System.out.println(max);
    }
    private static void dfs(long[][] arr,int k,long sum,int index) {
        boolean bb = false;
        for (int i = 0; i < arr.length; i++) {
            long y1 = minY;
            long y2 = maxY;
            minY = Math.min(arr[i][0], minY);
            maxY = Math.max(arr[i][0], maxY);
            long tmp = maxY - minY;
            if(!b[i] && tmp < k) {
                bb = true;
                b[i] = true;
                dfs(arr,k,sum + arr[i][1],i);
                b[i] = false;
            }
            minY = y1;
            maxY = y2;
        }
        max = Math.max(sum, max);
    }
}
